package com.sanqing.word;

import java.util.List;   
import java.util.Properties;  
import edu.stanford.nlp.ling.CoreAnnotations.PartOfSpeechAnnotation;  
import edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation;  
import edu.stanford.nlp.ling.CoreAnnotations.TextAnnotation;  
import edu.stanford.nlp.ling.CoreAnnotations.TokensAnnotation;  
import edu.stanford.nlp.ling.CoreLabel;  
import edu.stanford.nlp.pipeline.Annotation;  
import edu.stanford.nlp.pipeline.StanfordCoreNLP;   
import edu.stanford.nlp.util.CoreMap;
public class WordParse {
	public static String GetWordPos(String sentencestr,String keyWord)
    {
    	Properties props = new Properties();  
		props.put("annotators", "tokenize,ssplit,pos");  
		StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 
		String txtWord = sentencestr;  
		Annotation document = new Annotation(txtWord);  
		pipeline.annotate(document);  
		List<CoreMap> sentences = document.get(SentencesAnnotation.class);  
		for(CoreMap sentence: sentences)
		{  
		   for (CoreLabel token: sentence.get(TokensAnnotation.class)) 
		  {  
		     String word = token.get(TextAnnotation.class);  
		     String pos = token.get(PartOfSpeechAnnotation.class); 
		    if(word.equals(keyWord))
		    {
		    	return pos;
		    }
		  }
		     
		 }  
		return null;
		 
    
    }

}
